package cn.com.dstz.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class FillNameQuery{

	private FillNameQuery( ){}
	
	
	/**
	 * 根据指定的SQL查询条件和值列表填充Map
	 * @param SQL
	 * 			查询的SQL条件
	 * @param obj
	 * 		    值列表	
	 * @return
	 * 			封装入Map后的值
	 */
	public static Map<String, Object> fillValue(String SQL, Object ... obj){
		Map<String, Object> valueMap = new HashMap<String, Object>(4);
		
		Pattern pattern = Pattern.compile("[:][a-zA-Z0-9]+");
		Matcher matcher = pattern.matcher(SQL);
		
		String findGroup = null;
		
		for(int i = 0; i < obj.length; i++){
			if(matcher.find()){
				findGroup = matcher.group();
				valueMap.put(findGroup.substring(1, findGroup.length()), obj[i]);
			}
		}
		
		pattern = null;
		matcher = null;
		
		
		
		return valueMap;
	}
}
